using Framework;
using UnityEngine;
using UnityEngine.UI;

public class UIWindowBase : UIWindow
{
    protected override void OnStatusChanged(UIStatus value, UIStatus previous)
    {
        base.OnStatusChanged(value, previous);
        if (UIStatus.Open == value)
        {
            OnOpen();
        }
        else if (UIStatus.Prepare == value)
        {
            OnPrepare();
        }
        else if (UIStatus.Close == value)
        {
            OnClose();
        }
    }
    protected override void OnAwake()
    {
        base.OnAwake();
        if (this.Window != null)
        {
            var fields = this.Window.gameObject.GetComponent<GameObjectFields>();
            if (fields != null)
            {
                try
                {
                    InjectFields(fields);
                }
                catch (System.Exception)
                {
                    Debug.LogError(this.Window.name + "注入变量时出错");
                }
            }
            // Debug.LogError(this.Window.name + " Awake");
        }
    }
    protected virtual void InjectFields(GameObjectFields value)
    {

    }
    protected virtual void OnPrepare()
    {

    }
    protected virtual void OnOpen()
    {

    }
    protected virtual void OnClose()
    {

    }
    protected virtual void OnButtonClick(Button target)
    {

    }
}